<template>
  <view class="detail-container">
    <!-- 客户信息 -->
    <ve-card title="客户信息" type="none" fold>
      <ve-cell-val label="客户类型" :value="orderInfo.memberTypeName" />
      <ve-cell label="承租人">{{ orderInfo.memberName || '-' }} </ve-cell>
      <ve-cell-val label="联系电话" :value="orderInfo.memberPhone" />
      <ve-cell-val label="证件类型" :value="memberInfoDto.cardTypeName" />
      <ve-cell-val label="证件号" :value="orderInfo.cardNumber" />
    </ve-card>
    <!-- 租赁信息 -->
    <ve-card title="租赁信息" type="none" fold>
      <template #status>
        <view class="card__status">{{ orderInfo.statusName }}</view>
      </template>
      <ve-cell-val label="自营订单号" :value="orderInfo.orderNo" />
      <ve-cell-val label="订单来源" :value="orderInfo.orderSourceName" />
      <ve-cell label="订单获取方式">{{ orderInfo.orderAcquisitionTypeName || '-' }}</ve-cell>
      <ve-cell label="预计租赁周期">{{ (orderInfo.expectedUseCarTime || '-') + ' - ' + (orderInfo.expectedReturnCarTime || '-') }}</ve-cell>
      <ve-cell-val label="租期" :value="orderInfo.leaseNumberStr" />
      <ve-cell-val label="车型" :value="orderInfo.originalSiteModelName" />
      <ve-cell-val label="取车门店" :value="orderInfo.siteName" />
      <ve-cell-val label="上门取车地址" :value="orderInfo.address" />
      <ve-cell-val label="还车门店" :value="orderInfo.returnSiteName" />
      <ve-cell-val label="上门还车地址" :value="orderInfo.returnAddress" />
      <ve-cell-val label="车辆来源" :value="orderInfo.carSourceName" />
      <ve-cell label="车牌号">
        <text
          >{{ orderInfo.licenseNo || '-' }} <ve-tag color="red" v-if="orderInfo.orderCarLabel" :title="orderInfo.orderCarLabel" />
        </text>
      </ve-cell>
      <ve-cell-val label="交车车型" :value="orderInfo.modelName" />
      <ve-cell label="实际租赁周期">
        {{ orderInfo.realUseCarTime && orderInfo.realReturnCarTime ? orderInfo.realUseCarTime + ' - ' + orderInfo.realReturnCarTime : '-' }}
      </ve-cell>
      <!-- 取消状态 -->
      <ve-cell-val label="取消时间" v-if="orderInfo.status == -100" :value="orderInfo.cancelTime" />
      <ve-cell-val label="超时时长" :value="orderInfo.timeoutDuration" />
      <ve-cell-val label="订单备注" :value="orderInfo.remark" />
    </ve-card>
    <!-- 合同信息 -->
    <!-- <ve-card title="合同信息" type="none" fold v-model:initFold="initFold.a">
      <view class="contract-item" v-if="orderInfo.contractList">
        <ContractView :data="item" v-for="(item, index) in orderInfo.contractList" :key="index" />
      </view>
    </ve-card> -->
    <!-- 交车信息 -->
    <ve-card title="交车信息" type="none" fold v-model:initFold="initFold.b" v-if="orderInfo.giveCarInfoDto">
      <ve-cell-val label="交车里程" :value="orderInfo.giveCarInfoDto.giveCarMileage" unit="公里" />
      <ve-cell-val label="交车油(电)量" :value="orderInfo.giveCarInfoDto.giveFuelAmount" />
      <ve-cell-val label="交车人" :value="orderInfo.giveCarInfoDto.giveStaffName" />
      <ve-cell-val label="交车时间" :value="orderInfo.giveCarInfoDto.giveCarTime" />
      <ve-cell label="交车照片" layout="vertical">
        <ve-upload disabled v-model="orderInfo.giveCarInfoDto.giveFileIds"></ve-upload>
      </ve-cell>
      <ve-cell label="交车视频" layout="vertical">
        <ve-upload-video v-model="orderInfo.giveCarInfoDto.giveVideoFileIds" :readonly="true" />
      </ve-cell>
      <ve-cell-val label="交车备注" :value="orderInfo.giveCarInfoDto.remark" />
    </ve-card>
    <!-- 还车信息 -->
    <ve-card title="还车信息" type="none" fold v-model:initFold="initFold.c" v-if="orderInfo.returnCarInfoDto">
      <ve-cell-val label="还车里程" :value="orderInfo.returnCarInfoDto.returnCarMileage" unit="公里" />
      <ve-cell-val label="还车油(电)量" :value="orderInfo.returnCarInfoDto.returnFuelNum" />
      <ve-cell-val label="还车人" :value="orderInfo.returnCarInfoDto.returnStaffName" />
      <ve-cell-val label="还车时间" :value="orderInfo.returnCarInfoDto.returnCarTime" />
      <ve-cell label="还车照片" layout="vertical">
        <ve-upload v-model="orderInfo.returnCarInfoDto.returnFileIds" disabled />
      </ve-cell>
      <ve-cell label="还车视频" layout="vertical">
        <ve-upload-video v-model="orderInfo.returnCarInfoDto.returnVideoFileIds" :readonly="true" />
      </ve-cell>
      <ve-cell-val label="还车备注" :value="orderInfo.giveCarInfoDto.remark" />
    </ve-card>
  </view>
</template>

<script setup>
  import { onMounted, ref } from 'vue'
  import { getOrdrDetailsAPI } from '@/api/order/lOrder'
  import { serializeUrlParams } from '@/utils'
  import ContractView from './contract-view.vue'
  import { onLoad, onUnload } from '@dcloudio/uni-app'

  const props = defineProps({
    orderId: {
      type: String || Number,
    },
  })

  const memberInfoDto = ref({})
  const orderInfo = ref({})
  const initFold = ref({
    a: false,
    b: false,
    c: false,
  })
  const getDetail = async () => {
    const id = props.orderId
    const res = await getOrdrDetailsAPI({ id: id })
    if (res.code == 200) {
      const result = res.result
      memberInfoDto.value = result.memberInfoDto
      orderInfo.value = result.orderInfo
    }
  }
  // 上传驾驶证点击
  const uploadDriverLicenseFn = () => {
    let url = '/pages/order/upload-driver-license?'
    let urlParams = {
      memberId: memberInfoDto.value.id,
      driverFrontFileId: memberInfoDto.value.driverFrontFileId,
      driverReverseFileId: memberInfoDto.value.driverReverseFileId,
      autoUpload: true,
    }
    url += serializeUrlParams(urlParams)
    uni.navigateTo({ url: url })
  }
  onMounted(() => {
    getDetail()
  })
  onLoad(() => {
    // 车型选择完成
    uni.$on('uploadDriverLicenseOk', (option) => {
      const { driverFrontFileId, driverReverseFileId } = option
      // 更新驾驶证正反面 id
      memberInfoDto.value.driverFrontFileId = driverFrontFileId
      memberInfoDto.value.driverReverseFileId = driverReverseFileId
    })
    uni.$on('uploadIdCardOk', (option) => {
      const { idCardFrontFileId, idCardReverseFileId, cardType } = option
      // 更新身份证明正反面 id
      memberInfoDto.value.idCardFrontFileId = idCardFrontFileId
      memberInfoDto.value.idCardReverseFileId = idCardReverseFileId
      // 更新证件类型
      memberInfoDto.value.cardType = cardType
      memberInfoDto.value.cardTypeName = cardType == 0 ? '身份证' : '护照'
    })
  })
  onUnload(() => {
    uni.$off('uploadDriverLicenseOk')
    uni.$off('uploadIdCardOk')
  })
</script>

<style lang="scss" scoped>
  .detail-container {
    padding: 24rpx;
  }
  .contract-item {
    padding: 10rpx 0;
  }
  .card__status {
    height: 36rpx;
    line-height: 36rpx;
    margin-left: 16rpx;
    padding: 0 16rpx;
    background: linear-gradient(58deg, #ff5b60 0%, #ff7a66 100%);
    border-radius: 50rpx;
    // 字
    text-align: center;
    font-size: 24rpx;
    font-weight: 400;
    color: #ffffff;
  }
  .update {
    border-radius: 4rpx 4rpx 4rpx 4rpx;
    opacity: 1;
    border: 2rpx solid #3072f6;
    font-size: 24rpx;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #3072f6;
    line-height: 44rpx;
    margin-left: 16rpx;
    padding: 0 16rpx;
    word-break: keep-all;
  }
  .footerback {
    position: fixed;
    z-index: 999;
    width: 100%;
    bottom: 0;
    left: 0;
    background: #fff;
    padding: 24rpx;
  }
</style>
